import java.util.*;
import java.math.*;

class C{

	static long g[] = new long[1010];
	
	public static long func(int N, int round, long cap){
		int i,j;
		
		int next[] = new int[N+10];
		long score[] = new long[N+10];
		
		for(i=0;i<N;i++){
			j = i;
			long tmp = 0;
			while(tmp + g[j] <= cap) {tmp += g[j]; j = (j + 1) % N; if(j == i) break;}
			next[i] = j; score[i] = tmp;
		}
		
		int cur = 0, step = 0;
		long ans = 0;
		int visited[] = new int[N+10];
		
		for(i=0;i<N;i++) visited[i] = -1;
		while(true){
			if(step == round) return ans;
			if(visited[cur] == -1){
				visited[cur] = step;
				step++; ans += score[cur]; cur = next[cur];
			} else {
				int cycle = step - visited[cur];
				long tmp = 0;
				for(i=0;i<cycle;i++) {tmp += score[cur]; cur = next[cur];}
				ans += (round - step) / cycle * tmp;
				for(i=0;i<(round-step)%cycle;i++) {ans += score[cur]; cur = next[cur];}
				return ans;
			}
		}
	}

	public static void main(String[] args){
		int C,iter,i,N,round,cap;
		Scanner scan = new Scanner(System.in);
		
		C = scan.nextInt();
		for(iter=1;iter<=C;iter++){
			round = scan.nextInt(); cap = scan.nextInt(); N = scan.nextInt();
			for(i=0;i<N;i++) g[i] = scan.nextLong();
			long ans = func(N,round,cap);
			System.out.println("Case #" + iter + ": " + ans);
		}
	}
	
}
